Add support to stop SpinGroup and show interrupt debrief #569
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds new capabilities to
SpinGroup
:interrupt_debrief
: This option, specified when initializing theSpinGroup
, displays the debrief when theSpinGroup
is interrupted. This is useful to interrupt and see an error without waiting for all tasks to complete.SpinGroup#stop
,SpinGroup#stopped?
: Programmatic support for stopping aSpinGroup
. Exposing this method allows aSpinGroup
to be stopped when a task fails, which can be used to implement fail-fast behavior.SpinGroup::Task#on_done
: Support for a callback executed when a task transitions to done. This can be used to take action based on success or failure, and again can be used as part of an implementation of fail-fast behavior.The "primitives" above are implemented instead of a specific "fail-fast" option because they provide more flexibility.
The
#on_done
callback is specified on theTask
because it also provides more flexibility. With this approach, each task gets its own callback and additional state may be captured in the closure specified, whereas a callback on theSpinGroup
would be shared across all tasks and, even if it received the task as an argument, it would only have access to the current state of the task.